package com.xunfang.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.util.Properties;

public class DruidManger {

    //定义druid对象 - java管理连接池
    private static DataSource dataSource = null;

    static {
        //创建properties类的对象，用来操作 properties配置文件
        Properties pro = new Properties();
        try {
            pro.load(new FileInputStream("C:\\Users\\星星在唱歌\\Desktop\\学习\\LIU\\U2-day02\\src\\druid.properties"));
            //通过durid的工厂类创建
            dataSource = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //获取datascoure对象
    public static DataSource getDataSource(){
        return dataSource;
    }

    public static void main(String[] args) {
        DataSource dataSource = DruidManger.getDataSource();
        System.out.println("dataSource = " + dataSource);


    }
}
